package main

import (
	"Godemo/W1/demo/tree"
	"fmt"
)

type myTreeNode struct {
	node *tree.Node
}

// 后序遍历
func (myNode *myTreeNode) postOrder() {
	if myNode == nil || myNode.node == nil {
		return
	}

	left := myTreeNode{myNode.node.Left}
	right := myTreeNode{myNode.node.Right}
	left.postOrder()
	right.postOrder()
	myNode.node.Print()
}

func main() {
	var root tree.Node
	//		3
	//	   / \
	//	  0   5
	//	   \ /
	//	   2 4
	root = tree.Node{Value: 3}
	root.Left = &tree.Node{}
	root.Right = &tree.Node{5, nil, nil}
	root.Right.Left = new(tree.Node)
	root.Left.Right = tree.CreateTreeNode(2)

	root.Right.Left.SetValue(4)
	root.Print()
	fmt.Println()

	nodes := []tree.Node{
		{Value: 3},
		{},
		{6, nil, nil},
	}

	fmt.Println("nodes", nodes)

	root.Traverse()
	nodeCount := 0
	root.TraverseFunc(func(node *tree.Node) {
		nodeCount++
	})
	fmt.Println("Node Count:", nodeCount)

	myRoot := myTreeNode{&root}
	myRoot.postOrder()
	fmt.Println()
}
